<template>
    <div>
        <h1 style="text-align: center; color:chocolate;">管理员登录</h1>

        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>用户</td>
                    <td>
                        <input type="text" v-model="deng.name">
                    </td>
                </tr>
                <tr>
                    <td>密码</td>
                    <td>
                        <input type="password" v-model="deng.pwd">
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                       <button class="btn btn-info" @click="logn">登录</button>
                    </td>
                </tr>
            </tbody>
        </table>

    </div>
</template>

<script setup lang="ts">
import {ref,reactive,onMounted}from 'vue'
import axios from 'axios';
import { useRouter,useRoute } from 'vue-router';
import moment from 'moment';
import {useStore}from '@/stores/user'
const a=useStore();
const router=useRouter();
const route=useRoute();

let deng:any=reactive({
    name:'',
    pwd:''
})


//登录
const logn=()=>{
    console.log(deng);

    if(deng.name==''){
        alert('用户不能为空')
        return;
    }
    if(deng.pwd==''){
        alert('密码不能为空')
        return;
    }

    axios({
        url:'/api/Employee/Logn',
        method:'get',
        params:deng
    }).then(res=>{
        console.log(res);
        if(res.data==-1){
            alert('用户名不正确,或用户名不存在请联系相关人员更改')
        }else if(res.data==-2){
            alert('密码错误')
        }else{
            alert('登录成功')
            router.push('/employeeList')
            a.userIndex=res.data
        }
        
    }).catch(err=>{
        console.log(err);
        
    })
    
}

</script>

<style scoped>

</style>